<?php
class NavigationHelper extends AppHelper{

	var $helpers = array('Html');
	
	function buildNavigation($menu,$output=null,$options=null) {
		
		if($output==null){
			$output = '<div>';
		}else{
			$output .= '<div>';
		}

		foreach($menu as $key => $value){
			// set defaults
			$methods = array();
			$link = '';
			$class = "menu_element";
				
			if(isset($value['link'])){
				$link = $this->Html->link($key,$value['link']);
			}else{
				$link = $key;
			}
				
			if(isset($value['methods'])){
				$methods = explode(',', $value['methods']);
			}
			
			// check options here --> should be $this->params
			if(isset($options)){
				
			}
				
			$output .= '<div class="'.$class.'">'.$link.'</div>';
			
			// recursion
			if(isset($value['submenu'])){
				$submenu = $this->buildNavigation($value['submenu'],$output,$options);
				//foreach($value['submenu'] as $sub => $val){
					//$submenu .= ''..''
				//}
				$output .= '<div>'.$submenu.'</div>';
			}

			
			$output .= '</div>';
			
			return $output;
		}

	}


	function buildNavigation2($xml,$output=null, $navactive) {

		if($output==null){
			$output = '';
		}

		// set defaults
		$tmpOutput = '';
		$submenu = '';
		$class = '';
		$divClass = 'hide';
		$controller = array();
		$requestedController = $this->params['controller'];

		if(isset($xml['Menu'])){
			$xml = $xml['Menu'];
		}

		// walk through xml
		foreach($xml as $key => $value){

			if(is_array($value) && !empty($value)){

				if(isset($value['controller'])){
					$controller = explode(',',$value['controller']);
					if(in_array($requestedController, $controller)){
						$class = 'show';
						$divClass = 'show';
					}else{
						$class = 'hide';
						//$divClass = 'hide';
					}
				}

				if(in_array($value['name'],$navactive)){
					$class = ' show menuActive';
				}

				$tmpOutput .= '<span class="'.$class.'"><a href="'.URL_PREFIX.$value['link'].'">'.$value['name'].'</a></span>';
				$class = '';
				if(isset($value['Menu'])){
					$submenu .= $this->buildNavigation($value['Menu'],null,$navactive);
				}
			}
		}

		$output = '<div class="'.$divClass.'">';
		$output .= $tmpOutput;
		$output .= '</div>';
		$output .= $submenu;
		return $output;
	}


}



?>